package test2;
import java.util.Scanner;
public class test2 {
    public static int maxsum(int arr[]){
        int a = arr.length;
        int sum=0, maxsum =0;
        int i,j,k;
        for(i=0;i<a;i++){
            for(j=i;j<a;j++){
                sum=0;
                for(k=i;k<j;k++){
                    sum=arr[k]+sum;
                }
                if(sum> maxsum){
                    maxsum =sum;
                }
            }
        }
        return maxsum;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int number=Integer.parseInt(sc.next());
        int[] num=new int[number];
        for(int i=0;i<number;i++){
            num[i]=(int)sc.nextInt();
        }
        System.out.println(maxsum(num));
    }

}
